using Godot;
using System;

public partial class UiMinitask : Control
{
	private Label taskname;
	private Label tasktarget;
	private Player _player;

	private TaskManager _taskManager;
	// Called when the node enters the scene tree for the first time.
	public override void _Ready()
	{
		taskname = GetNode<Label>("%taskname");
		tasktarget = GetNode<Label>("%tasktarget");
		var Game = GetNode<Game>("/root/Game");
		_player = Game.get_player();
		_taskManager = _player.GetNode<TaskManager>("%TaskManager");
		Updatetask();
	}

	// Called every frame. 'delta' is the elapsed time since the previous frame.
	public override void _Process(double delta)
	{
		Updatetask();
	}

	public void Updatetask()
	{
		var children = _taskManager.GetChildren();
		foreach (var child in children)
		{
			Tasks task = child as Tasks;
			if(task.follow == true)
			{
				taskname.Text = task.name;
				tasktarget.Text = task.description;
				break;
			}
			if(child == children[children.Count-1]&&task.follow!=true)
			{
				taskname.Text = "";
				tasktarget.Text = "";
			}
		}
	}
}
